#pragma once
#ifndef __G_TASK_RESULT_H__
#define __G_TASK_RESULT_H__

#include <atomic>

#include "GTypes.h"

namespace GEngine
{
	enum GTaskState
	{
		G_TS_IDLE		= 0,
		G_TS_SCHEDULED	= 1,
		G_TS_COMPLETED	= 2,
	};

	class CACHELINE_ALIGNED GTaskResult
	{
	friend class GTask;
	friend class GWorkerThread;

	typedef std::atomic<GInt32> AtomicInt;
	typedef std::atomic<GTaskState> AtomicState;

	private:
		AtomicInt		RefCount;
		AtomicState		State;

		void			IncreaseRef();
		void			DecreaseRef();

	public:
						GTaskResult();
						~GTaskResult();

		GTaskState		GetState() const;

		void			Reset();

		static bool		CheckComplete(const GTaskResult& Result);
	};
}

#endif